package com.rjwh.dingdong.client.mvp.model.impl;

import com.aishua.lib.task.AsResult;
import com.rjwh.dingdong.client.constant.NetConstant;
import com.rjwh.dingdong.client.mvp.BaseModel;
import com.rjwh.dingdong.client.mvp.BasePresenter;
import com.rjwh.dingdong.client.mvp.model.IHomeWorkModel;
import com.rjwh.dingdong.client.network.HttpWebService;
import com.rjwh.dingdong.client.network.HttpWebServiceCallBack;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 王小珂
 * @ClassName HomeWorkModel
 * @Description
 * @date 2017-1-4
 * @history 2017-1-4 author: description:
 */

public class HomeWorkModel extends BaseModel implements IHomeWorkModel, HttpWebServiceCallBack {

    public HomeWorkModel(BasePresenter basePresenter) {
        super(basePresenter);
    }

    /**
     * 获取作业列表
     *
     * @param agecode
     * @param category
     * @param pageindex
     */
    @Override
    public void doGetHomeWorkList(int agecode, String category, int pageindex, boolean isRefresh) {
        Map<String, String> params = new HashMap<>();
        params.put("agecode", String.valueOf(agecode));
        params.put("category", category);
        params.put("pageindex", String.valueOf(pageindex));
        HttpWebService.getDataFromServer(NetConstant.GETHOMEWORKLIST, params, isRefresh, this);
    }

    /**
     * 注册作业
     *
     * @param bookid
     * @param category
     */
    @Override
    public void doHomeWorkAssign(String bookid, String category) {
        Map<String, String> params = new HashMap<>();
        params.put("bookid", bookid);
        params.put("category", category);
        HttpWebService.getDataFromServer(NetConstant.HOMEWORK_ASSIGN, params, true, this);
    }

    @Override
    public void onServerDataAcquired(int businessType, AsResult mAsResult, boolean isRefresh) {

        if (getBasePresenter() != null) {
            getBasePresenter().onServerDataAcquired(businessType, mAsResult, isRefresh);
        }
    }
}
